package sa.com.sure.ejtimaa.components;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;


import sa.com.sure.ejtimaa.R;
import sa.com.sure.ejtimaa.database.MeetingAttendees;
import sa.com.sure.ejtimaa.model.MeetingAttendeeInfo;
import sa.com.sure.ejtimaa.model.MeetingInfo;
import sa.com.sure.ejtimaa.model.MemberInfo;
import sa.com.sure.ejtimaa.database.Members;
import android.content.Context;
import android.database.SQLException;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MeetingAttendanceListComponent extends LinearLayout {

	private Context context = null;
	
	private LinearLayout list = null;
	
	private List<MeetingAttendeeInfo> meetingAttendees = new ArrayList<MeetingAttendeeInfo>();
	
	
	public MeetingAttendanceListComponent(Context context,AttributeSet attrs){	
		
		super(context,attrs);		
		
		final LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.attendance_list_component, this);
        
        this.context = context;                                      
        
        list = (LinearLayout) this.findViewById(R.id.list) ;
	
	}
	
	
	public void SetData(MeetingInfo item) throws SQLException, ParseException{
			
		meetingAttendees = MeetingAttendees.Instance.GetItemsByMeetingIDAndAttended(item.GetMeetingID(), true);
		
		list.removeAllViews();
		
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
				
					
		for (final MeetingAttendeeInfo meetingAttendee : meetingAttendees) {
			
			View v = inflater.inflate(R.layout.attendance_list_item, null);											
					
			String memberId = meetingAttendee.GetMemberID();
			
			MemberInfo member = Members.Instance.GetItemByMemberID(memberId);
			
			TextView tvFullName = (TextView) v.findViewById(R.id.tvFullName);
			TextView tvMobile = (TextView) v.findViewById(R.id.tvMobile);
			TextView tvEmail = (TextView) v.findViewById(R.id.tvEmail);
			
			tvFullName.setText(member.GetFullName());
			tvMobile.setText(member.GetMobile());
			tvEmail.setText(member.GetEmail());
			
			list.addView(v);
		}
		

	}
	

	
}
